<!DOCTYPE html>
<html>
{include file="public/head"}
<body>

{include file="public/nav"}

{include file="community/nav"}
<div class="layui-container">
  <div class="layui-row layui-col-space15">
    <div class="layui-col-md8" >
       <div class="fly-panel detail-box"> 
   <h1>{:htmlspecialchars($article.title)}</h1> 
   <div class="fly-detail-info"> 
    {eq name="article.type" value="0"}<span class="layui-badge layui-bg-green fly-detail-column"> 普通讨论 </span> {/eq}
    {if condition="$article.type>0"}<span class="layui-badge layui-bg-blue fly-detail-column"> 问题讨论 </span>
    <a href="{:url('web/Problem/problem','pid='.$article.type)}">
        <span class="layui-badge layui-bg-blue fly-detail-column">Problem-{$article.type} </span>
        </a>
    {/if}
 

    <span class="fly-list-nums">
        {if condition="$is_yours||$is_admin"}
        <a href="javascript:;" id="hide-show"><i class="layui-icon" id="hide-show-ico" status='{$article.status}'>{if condition="$article.status==1"}&#xe627;{else /}&#xe626;{/if}</i><span id='hide-show-text'>显示</span></a>
        {/if}
        {if condition="$is_yours||$is_admin"}
        <a href="javascript:;" id='topic-del'><i class="layui-icon">&#xe640;</i>删除</a>
        {/if}
        {if condition="$is_yours"}
        <a href="{:URL('web/Community/editor_post',['tid'=>$article.topic_id])}"><i class="layui-icon">&#xe642;</i>编辑</a>
        {/if}
    </span> 
   </div> 
   <div class="detail-about"> 
    <a class="fly-avatar" href="{:url('web/Account/info','user_id='.$article['user_id'])}"> <img src="__STATIC__/../upload/users/head/{$article.head}" alt="{$article.user_id}" /> </a> 
    <div class="fly-detail-user"> 
     <a href="{:url('web/Account/info','user_id='.$article['user_id'])}" class="fly-link"> <cite>{$article.user_id}</cite>  </a> 
     <span>发布时间:{:date('Y-m-d H:i:s',$article.in_time)}</span> 
    </div> 
    <div class="detail-hits" id="LAY_jieAdmin" data-id="24241"> 
     <span style="padding-right: 10px; color: #FF7200">讨论一下</span> 
    </div> 
   </div> 
   <div class="detail-body layui-text photos">
       <div id="article-content" class="nyoj-clear-width" style='width:inherit;'>
           <textarea style="display:none;">{:htmlspecialchars($article.content)}</textarea>
       </div>
     <div style="text-align: center;">
         <br />
         <span onclick='sss()'><i class="iconfont icon-zan" style="font-size: 30px;cursor: pointer;" title="打赏他一个OJ币">支持数 <span id='support-num'>{$article.support}</span></i></span>
     </div>
   </div> 
   
  </div>
        <div class="fly-panel detail-box" id="flyReply">
        <fieldset class="layui-elem-field layui-field-title" style="text-align: center;">
          <legend>回帖</legend>
        </fieldset>

            <ul id="topic-reply" class="nyoj-reply-list">
         
            </ul>
        
        <div class="layui-form layui-form-pane"> 
            <form>
                <input name="topic_id" value="{$article.topic_id}" class="layui-hide" />
                <div class="layui-form-item layui-form-text">
                    <div class="">
                        <textarea id="nyoj_content" name="content" required lay-verify="content" placeholder="请输入内容 [请使用markdown语法]"  class="layui-textarea fly-editor" style='height: 150px;'></textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <input type="hidden" name="topic_id" value="{$article.topic_id}">
                    <a class="layui-btn"  lay-submit lay-filter="reply-submit">提交回复</a>
                </div>
            </form>
        </div>
      </div>
        
        
        
    </div>
 {include file="public/side-bar"}
  </div>
</div>
 {include file="public/foot"}
</body>
{include file="community/js"}
<script src="__STATIC__/markdown/examples/js/jquery.min.js"></script>
 <script src="__STATIC__/markdown/editormd.min.js"></script>
 
        <script src="__STATIC__/markdown/lib/marked.min.js"></script>
        <script src="__STATIC__/markdown/lib/prettify.min.js"></script>
        
        <script src="__STATIC__/markdown/lib/raphael.min.js"></script>
        <script src="__STATIC__/markdown/lib/underscore.min.js"></script>
        <script src="__STATIC__/markdown/lib/sequence-diagram.min.js"></script>
        <script src="__STATIC__/markdown/lib/flowchart.min.js"></script>
        <script src="__STATIC__/markdown/lib/jquery.flowchart.min.js"></script>
<script>
    

// 回复的加载
layui.use('flow', function(){
  var flow = layui.flow;
   var $ = layui.jquery; 
  flow.load({
    elem: '#topic-reply' //流加载容器
    ,isAuto:false
    ,done: function(page, next){ //执行下一页的回调
      //模拟数据插入
        $.get("{:url('web/Message/get_more_reply')}/tid/{$article.topic_id}/page/"+page, function(res){
        next(res.html, page < res.pages);
        markdowntohtml();
        });
        
    }
  });
  
  
});



//点赞回复
function supportreply(id){
    layui.use(['jquery','layer'],function(){
        var $=layui.jquery;
        var layer=layui.layer;
        $.ajax({
           url:"{:url('web/Message/reply_support')}/"+id,
           success:function(res){
               if(res.code===0){
                   layer.msg(res.msg);
                   var sp=$('#reply-support-'+id).html();
                   $('#reply-support-'+id).html(++sp);
               }
               else {
                   layer.msg(res.msg);
               }
           }
        });
    });
}

layui.use(['form','jquery','layer'],function(){
    var $=layui.jquery;
    var layer=layui.layer;
    $("#topic-del").click(function(){ //这里是删除的操作
        layer.confirm('真的要删掉吗? ( >﹏<。)～呜呜呜…… ',{
                btn: ['确认','取消'] //按钮
            }
                ,function(){
                    //console.log('id='+id);
                    $.get('/api/topic-set-0-{$article.topic_id}',null,function(res){
           if(res.code==0){
               layer.msg(res.msg);
               var code='location.href=\''+res.url+'\';';
               setTimeout(code,1000);
           }
           else {
               layer.msg(res.msg);
           }
       });
                }
                ,function(){
                }
            );
       
    });
    $("#hide-show").click(function(){ //隐藏 显示
       var now=$('#hide-show-ico').attr('status');
       console.log(now);
       if(now==='1'){
           $.get('/api/topic-set-1-{$article.topic_id}',null,function(res){
           if(res.code===0){
               layer.msg(res.msg);
               $('#hide-show-ico').html('&#xe626;');
               $('#hide-show-ico').attr('status','0');
           }
           else {
               layer.msg(res.msg);
           }
        });
       }
       else{
           $.get('/api/topic-set-2-{$article.topic_id}',null,function(res){
           if(res.code===0){
               layer.msg(res.msg);
              $('#hide-show-ico').html('&#xe627;');
              $('#hide-show-ico').attr('status','1');
           }
           else {
               layer.msg(res.msg);
           }
       });
       }
       
    });

       
    var form=layui.form;
    form.on('submit(reply-submit)',function(data){
        $.ajax({
            url:'{:url("web/Message/reply")}',
            data:data.field,
            success:function(res){
                if(res.code==0){
                    layer.msg(res.msg);
                    setTimeout('location.reload();',1000);
                }
                else {
                    layer.msg(res.msg);
                }
            }
        })
    });
});

    
    function sss(){
        layui.use('jquery',function(){
            var $=layui.jquery;
            $.ajax({ url:"{:url('web/Community/support','tid='.$article['topic_id'])}",success:function(res){
                    if(res.code===0){
                            layui.use('layer', function(){
                            var layer = layui.layer;
                            layer.msg(res.msg);
                            $('#support').text(parseInt($("#support").text())+1);
                            var ss=parseInt($('#support-num').html());
                            $('#support-num').html(++ss);
                        }); 
                    }
                    else {
                        layui.use('layer', function(){
                            var layer = layui.layer;
                            layer.msg(res.msg);
                        });  
                    }
		}});
        });
    }

function do_reply_js(uid){
    layui.use('jquery',function(){
        var $=layui.jquery;
        var to='@'+uid+":";
        var orin=$('#nyoj_content').val();
        $("#nyoj_content").focus();
        if(orin.indexOf(to)==-1){
            $('#nyoj_content').val(to+orin);
        }
    });
}
    layui.use(['jquery','layer'],function(){
        var $=layui.jquery;
        var layer=layui.layer;
        $("#topic-reply").delegate(".nyoj-reply-del","click",function(){
            var id=$(this).attr('reply-id');
            //console.log('id='+id);
            //return ;
            layer.confirm('真的要删掉吗? ( >﹏<。)～呜呜呜…… ',{
                btn: ['确认','取消'] //按钮
            }
                ,function(){
                    console.log('id='+id);
                    $.get('/api/delreply/'+id,null,function(res){
                    if(res.code===0){
                        layer.msg(res.msg);
                        $('#replyid-'+id).remove();
                    } 
                    else {
                        layer.msg(res.msg);
                    }
                    });
                }
                ,function(){
                }
            );
            
        });
        
        
    });

</script>



        <script type="text/javascript">
            editormd.urls.atLinkBase = "{:url('web/Account/info')}/";
        function markdowntohtml(){
            $(".needtohtml").each(function(){
           var $there=$(this);
           var id=$there.attr('id');
           $there.removeClass('needtohtml');
           editormd.markdownToHTML(id, {
                            htmlDecode      : "style,script,iframe",  // you can filter tags decode
                            emoji           : true,
                            taskList        : true,
                            codeFold         : true,
                            tex             : true,  // 默认不解析
                            flowChart       : true,  // 默认不解析
                            sequenceDiagram : true,  // 默认不解析
                            path            : "__STATIC__/markdown/lib/",
                        });
        });
        }
        editormd.markdownToHTML('article-content', {
                            htmlDecode      : "style,script,iframe",  // you can filter tags decode
                            emoji           : true,
                            taskList        : true,
                            tex             : true,  // 默认不解析
                            flowChart       : true,  // 默认不解析
                            sequenceDiagram : true,  // 默认不解析
                            path            : "__STATIC__/markdown/lib/",
                        });
        </script>

</html>
